<template>
  <div>
    <van-nav-bar
      title="新增地址"
      left-arrow
      fixed
      placeholder
      @click-left="onClickLeft"
    />
    <!-- 添加地址 -->
    <van-address-edit
      :area-list="areaList"
      show-set-default
      :address-info=addrinfo
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="lpkaddSave"
    />
  </div>
</template>

<script>
import { areaList } from '@vant/area-data';
import { Post } from '../gp';
export default {
  data() {
    return {
      areaList,
      addrinfo:{}
    };
  },
  methods: {
    onClickLeft() {   //  返回地址管理
      this.$router.push("/address");
    },
    lpkaddSave(content) {
      console.log(content);
      let data={};
      data.user_id=this.$store.state.id;
      data.receiver=content.name;
      data.province=content.province;
      data.city=content.city;
      data.area=content.county;
      data.areacode=content.araeCode;
      data.addr=content.addressDetail;
      data.cellphone=content.tel;
      data.is_default=content.isDefault==false?0:1;
      Post(
        '/addr/add',data
      ).then(res=>{
        console.log(res);
        console.log('添加成功');
        if(res.data.code==200){
          this.$router.push('/address')
        }
      })
    }
  },
};
</script>

<style lang="scss">
//顶部返回箭头样式
.van-nav-bar__placeholder > div > div > .van-nav-bar__left {
  i {
    color: black;
  }
}
</style>